package com.zenithmind.version.pojo.domain;

import com.baomidou.mybatisplus.annotation.TableName;
import com.zenithmind.common.base.BaseEntity;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 仓库URL信息实体类 - 遵循单一职责原则，专门处理仓库URL相关信息
 * 
 * @author ZenithMind Team
 * @since 2025-01-09
 */
@Data
@EqualsAndHashCode(callSuper = true)
@TableName("version_repository_url")
@Schema(description = "仓库URL信息实体")
public class RepositoryUrl extends BaseEntity {

    /**
     * 仓库ID
     */
    @Schema(description = "仓库ID")
    private String repositoryId;

    /**
     * 克隆URL
     */
    @Schema(description = "克隆URL")
    private String cloneUrl;

    /**
     * SSH URL
     */
    @Schema(description = "SSH URL")
    private String sshUrl;

    /**
     * 获取指定协议的URL
     * 
     * @param protocol 协议类型（http/ssh）
     * @return 对应的URL
     */
    public String getUrlByProtocol(String protocol) {
        if ("ssh".equalsIgnoreCase(protocol)) {
            return this.sshUrl;
        } else {
            return this.cloneUrl;
        }
    }
    
    /**
     * 检查是否配置了HTTP克隆URL
     * 
     * @return 是否配置了HTTP URL
     */
    public boolean hasHttpUrl() {
        return this.cloneUrl != null && !this.cloneUrl.trim().isEmpty();
    }
    
    /**
     * 检查是否配置了SSH URL
     * 
     * @return 是否配置了SSH URL
     */
    public boolean hasSshUrl() {
        return this.sshUrl != null && !this.sshUrl.trim().isEmpty();
    }
    
    /**
     * 验证URL格式
     * 
     * @return 是否所有URL格式都正确
     */
    public boolean isValidUrls() {
        boolean httpValid = cloneUrl == null || cloneUrl.startsWith("http://") || cloneUrl.startsWith("https://");
        boolean sshValid = sshUrl == null || sshUrl.startsWith("git@") || sshUrl.startsWith("ssh://");
        return httpValid && sshValid;
    }
}
